<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <brother1></brother1>
    <hr />
    <brother2></brother2>
  </div>
  <template id="brother1">
    <div>
      <input type="text" placeholder="兄弟1" :value="value" @input="brother1Inp">
    </div>
  </template>
  <template id="brother2">
    <div>
      <input type="text" placeholder="兄弟2" :value="value" @input="brother2Inp">
    </div>
  </template>
  <script src="./vue.js"></script>
  <script>
    const bus = new Vue()
    new Vue({
      el: '#app',
      components: {
        brother1: {
          template: '#brother1',
          mounted() {
            bus.$on('brother2Inp', val => {
              this.value = val
            })
          },
          data() {
            return {
              value: ''
            }
          },
          methods: {
            brother1Inp(e) {
              this.value = e.target.value
              bus.$emit('brother1Inp', e.target.value)
            }
          }
        },
        brother2: {
          template: '#brother2',
          data() {
            return {
              value: ''
            }
          },
          mounted() {
            bus.$on('brother1Inp', val => {
              this.value = val
            })
          },
          methods: {
            brother2Inp(e) {
              bus.$emit('brother2Inp', e.target.value)
            }
          },
        }
      }
    })
  </script>
</body>

</html>